# Aller chercher les nouvelles(Le journal) sur TV5.org

import mc
import re
import time
import traceback
import sys

mc.ActivateWindow(14000)

TV5_JOURNAL_BASE_URL = "http://www.tv5.org"
TV5_JOURNAL_VIDEOS = "http://vodflash.tv5monde.com"
TV5_JOURNAL = "http://www.tv5.org/cms/chaine-francophone/info/p-1908-Accueil.htm"



def getJournal():
	emissions = []

	sg = mc.Http()
	html = sg.Get(TV5_JOURNAL)
	results = re.compile('<li .+?><a href="(.+?)" ><strong>(.+?)</strong></a>.+?</li>').findall(html)

	emissions = mc.ListItems()

	for url, name in results:
		
		item = mc.ListItem(mc.ListItem.MEDIA_UNKNOWN)
		item.SetLabel(name)
		item.SetPath(TV5_JOURNAL_BASE_URL + url)
		item.SetProperty('flag','playJournal') #FLAG
		emissions.append(item)
		
	
	
	return emissions
	


def getVideos(url):
	videos = []
	
	mc.ShowDialogOk('Debug!', url)

	sg = mc.Http()
	html = sg.Get(url)
	
	mc.LogDebug("Debug URL: " + url)	
	results = re.compile('file=(.+?).flv').findall(html)
	
	videos = mc.ListItems()
	for flv in results:
		mc.LogDebug("Debug FLV: " + TV5_JOURNAL_VIDEOS + flv + '.flv')	
		return TV5_JOURNAL_VIDEOS + flv + '.flv'

def playVideo(url):

	
	
	objVideo = mc.ListItem(mc.ListItem.MEDIA_UNKNOWN)
	objVideo.SetLabel('Mon Video')
	objVideo.SetPath(url)
		
		
	mc.GetPlayer().Play(objVideo)


